package com.chrissy.music.common.enums;

import lombok.Getter;

import java.util.Objects;

/**
 * 系统状态码
 * 200：成功
 * 500：失败
 * 403：token过期
 * @author Johnson
 */
@Getter
public enum HttpCodeEnum {

    /**
     * 成功
     */
    SUCCESS(200, "成功"),
    /**
     * 失败
     */
    ERROR(500, "系统异常，稍后重试"),
    /**
     * token过期
     */
    TOKEN_INVALID(403, "当前登录已过期，请重新登录");

    private Integer code;
    private String message;

    HttpCodeEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    void setCode(Integer code) {
        this.code = code;
    }

    void setMessage(String message) {
        this.message = message;
    }

    public static String getValue(Integer index) {
        for (HttpCodeEnum dataSourceEnum : HttpCodeEnum.values()) {
            if (Objects.equals(dataSourceEnum.getCode(), index)) {
                return dataSourceEnum.getMessage();
            }
        }
        return null;
    }
}
